import java.util.Arrays;
class Student implements Comparable<Student> {
    public String name;
    public int age;
    public int score;

    public Student(String name, int age, int score) {
        this.name = name;
        this.age = age;
        this.score = score;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", score=" + score +
                '}';
    }

    /* @Override
     public int compareTo(Student o) {
         if(this.age > o.age) {//this表示的是：谁调用这个compareTo这个方法，谁就是this
             //this表示的就是student[0],o表示的就是student[1]
             return 1;
         }else if(this.age < o.age){
             return -1;
         }else {
             return 0;
         }
     }*/
    @Override
    public int compareTo(Student o) {
        if (this.name.compareTo(o.name) > 0) {
            return 1;
        } else if (this.name.compareTo(o.name) < 0) {
            return -1;
        } else {
            return 0;
        }
    }
}

public class Test {
    public static void main(String[] args) {
        Student[] student =new Student[3];
        student[0] = new Student("zhangsan",19,10);
        student[1] = new Student("lisi",29,20);
        student[2] = new Student("wangwu",39,5);
//        System.out.println(student[0].compareTo(student[1]));
        Arrays.sort(student);
        System.out.println(Arrays.toString(student));
    }
    public static void main1(String[] args) {
        int[] array = {1,3,2,10,5,3,7};
        Arrays.sort(array);
        System.out.println(Arrays.toString (array));
    }
}
